move initialization of OptionInt/Double parameters to constructor (#1364)
authortsteven4 <13596209+tsteven4@users.noreply.github.com>
Thu, 31 Oct 2024 15:41:17 +0000 (09:41 -0600)
committerGitHub <noreply@github.com>
Thu, 31 Oct 2024 15:41:17 +0000 (09:41 -0600)
* move init of OptionInt/Double parms to ctor

except for id, which isn't known by formats/filters.
Also, move validation of OptionInt/Double strings to Option
class, where it can be maintained in parallel with the conversion
routines.

* init Option id in init_vec, init_filter_vec.

also
fix -Wclazy-unused-non-trivial-variable.
add test of Option error detection.

23 files changed:
arcdist.h
defs.h
filter_vecs.cc
filter_vecs.h
garmin.h
garmin_gpi.h
gdb.h
height.h
interpolate.h
main.cc
option.cc
option.h
ozi.h
position.h
radius.h
reference/badopt1.txt [new file with mode: 0644]
reference/badopt2.txt [new file with mode: 0644]
reference/badopt3.txt [new file with mode: 0644]
reference/badopt4.txt [new file with mode: 0644]
smplrout.h
testo.d/vecs.test [new file with mode: 0644]
vecs.cc
vecs.h

index 717b6efcae827d8f50a7ce61d7c4473f46d45c8e..868b3d7f08b5b7cecb1d80aaa2b2b3b4410eaea4 100644 (file)
--- a/arcdist.h
+++ b/arcdist.h
@@ -61,7 +61,7 @@ private:
   /* Data Members */
 
   double pos_dist{};
-  OptionDouble distopt;
+  OptionDouble distopt{true};
   OptionString arcfileopt;
   OptionBool rteopt;
   OptionBool trkopt;
@@ -71,7 +71,7 @@ private:
 
   QVector<arglist_t> args = {
     {
-      "file", &arcfileopt,  "File containing vertices of arc",
+      "file", &arcfileopt, "File containing vertices of arc",
       nullptr, ARGTYPE_FILE, ARG_NOMINMAX, nullptr
     },
     {
@@ -84,7 +84,7 @@ private:
     },
     {
       "distance", &distopt, "Maximum distance from arc",
-      nullptr,  ARGTYPE_ALLOW_TRAILING_DATA | ARGTYPE_STRING | ARGTYPE_REQUIRED, ARG_NOMINMAX, nullptr
+      nullptr, ARGTYPE_STRING | ARGTYPE_REQUIRED, ARG_NOMINMAX, nullptr
     },
     {
       "exclude", &exclopt, "Exclude points close to the arc", nullptr,
diff --git a/defs.h b/defs.h
index 34baa610fe501b66b1ae36208e29dd401adbc16e..879a0f257b94d3558648771143233cfcad59b3fd 100644 (file)
--- a/defs.h
+++ b/defs.h
@@ -866,18 +866,8 @@ extern posn_status tracking_status;
  * for "groups" of exactly one option. */
 #define ARGTYPE_BEGIN_REQ  0x04000000U
 #define ARGTYPE_END_REQ    0x02000000U
-/* For integer conversions specify the base to allow strict error checking and
- * proper conversion in Vecs */
-#define ARGTYPE_BASE_10   0x00000000U
-#define ARGTYPE_BASE_AUTO 0x00100000U
-#define ARGTYPE_BASE_16   0x00200000U
-
-/* For integer and double conversions is trailing data allowed?
- * This allows strict error checking in Vecs */
-#define ARGTYPE_ALLOW_TRAILING_DATA 0x00400000U
 
 #define ARGTYPE_TYPEMASK 0x00000fffU
-#define ARGTYPE_BASEMASK 0x00300000U
 #define ARGTYPE_FLAGMASK 0xfffff000U
 
 #define ARG_NOMINMAX nullptr, nullptr
index 5f7a42a96d366c9609f61bb28252f8981167dcf5..0741a84b20afa6fc5d59262a3656babe2ec194b4 100644 (file)
@@ -270,11 +270,18 @@ void FilterVecs::free_filter_vec(Filter* flt)
   Vecs::free_options(flt->get_args());
 }
 
-void FilterVecs::init_filter_vec(Filter* flt)
+void FilterVecs::init_filter_vec(Filter* flt, const QString& fltname)
 {
   QVector<arglist_t>* args = flt->get_args();
   if (args && !args->isEmpty()) {
     assert(args->isDetached());
+    for (auto& arg : *args) {
+      if (arg.argval != nullptr) {
+        arg.argval->reset();
+        QString id = QStringLiteral("%1(%2)").arg(fltname, arg.argstring);
+        arg.argval->init(id);
+      }
+    }
   }
 }
 
@@ -282,7 +289,7 @@ void FilterVecs::init_filter_vecs()
 {
   for (const auto& vec : d_ptr_->filter_vec_list) {
     if (vec.vec != nullptr) {
-      init_filter_vec(vec.vec);
+      init_filter_vec(vec.vec, vec.name);
     }
   }
 }
index 7f9b8db7387d2b8144be99e6a007ec3a17b95648..906aba26e982cd1d05e5195c90246fc3c10ffeb6 100644 (file)
@@ -70,7 +70,7 @@ public:
   static void prepare_filter(const fltinfo_t& fltdata);
   fltinfo_t find_filter_vec(const QString& fltargstring);
   static void free_filter_vec(Filter* flt);
-  static void init_filter_vec(Filter* flt);
+  static void init_filter_vec(Filter* flt, const QString& fltname);
   void init_filter_vecs();
   static void exit_filter_vec(Filter* flt);
   void exit_filter_vecs();
index 0be8a5ff15f80c8e7181f7d6a89584bc3c7f9a37..4d503226c717d887f3884b6237dca3f561147de2 100644 (file)
--- a/garmin.h
+++ b/garmin.h
@@ -128,7 +128,7 @@ private:
   OptionBool snwhiteopt;
   OptionString deficon;
   OptionInt categoryopt;
-  OptionInt categorybitsopt;
+  OptionInt categorybitsopt{false, 0};
   OptionInt baudopt;
   OptionString opt_codec;
   int baud = 0;
@@ -171,7 +171,7 @@ private:
     },
     {
       "bitscategory", &categorybitsopt, "Bitmap of categories",
-      nullptr, ARGTYPE_BASE_AUTO | ARGTYPE_INT, "1", "65535", nullptr
+      nullptr, ARGTYPE_INT, "1", "65535", nullptr
     },
     {
       "baud", &baudopt, "Speed in bits per second of serial port (baud=9600)",
index 8b380c8365f6b4384b612872a585a625621c261a..b8ddd9587c3806219cc65b31f85ccf7063ba7767 100644 (file)
@@ -318,8 +318,8 @@ private:
   OptionBool opt_unique;
   OptionBool opt_alerts;
   OptionString opt_units;
-  OptionDouble opt_speed;
-  OptionDouble opt_proximity;
+  OptionDouble opt_speed{true};
+  OptionDouble opt_proximity{true};
   OptionInt opt_sleep;
   OptionString opt_lang;
   OptionString opt_writecodec;
@@ -357,7 +357,7 @@ private:
     },
     {
       "proximity", &opt_proximity, "Default proximity",
-      nullptr,  ARGTYPE_ALLOW_TRAILING_DATA | ARGTYPE_STRING, ARG_NOMINMAX, nullptr
+      nullptr, ARGTYPE_STRING, ARG_NOMINMAX, nullptr
     },
     {
       "sleep", &opt_sleep, "After output job done sleep n second(s)",
@@ -365,7 +365,7 @@ private:
     },
     {
       "speed", &opt_speed, "Default speed",
-      nullptr,  ARGTYPE_ALLOW_TRAILING_DATA | ARGTYPE_STRING, ARG_NOMINMAX, nullptr
+      nullptr, ARGTYPE_STRING, ARG_NOMINMAX, nullptr
     },
     {
       "unique", &opt_unique, "Create unique waypoint names (default = yes)",
diff --git a/gdb.h b/gdb.h
index a2bcb968020aba85acff093f460a7be53515524d..37025f79e34eb85ebbdc89c9716645e8a75b80c7 100644 (file)
--- a/gdb.h
+++ b/gdb.h
@@ -166,7 +166,7 @@ private:
   OptionInt gdb_opt_ver;
   OptionBool gdb_opt_via;
   OptionBool gdb_opt_roadbook;
-  OptionInt gdb_opt_bitcategory;
+  OptionInt gdb_opt_bitcategory{false, 0};
   OptionBool gdb_opt_drop_hidden_wpt;
 
   int waypt_flag{};
@@ -187,7 +187,7 @@ private:
     },
     {
       "bitscategory", &gdb_opt_bitcategory, "Bitmap of categories",
-      nullptr, ARGTYPE_BASE_AUTO | ARGTYPE_INT, "1", "65535", nullptr
+      nullptr, ARGTYPE_INT, "1", "65535", nullptr
     },
     {
       "ver", &gdb_opt_ver,
index 9aedb58eb99232100b4663887101b9ed4d8e770b..ab58174610e2b88a832643d1ee81e9f9cc277e01 100644 (file)
--- a/height.h
+++ b/height.h
@@ -47,7 +47,7 @@ public:
   void process() override;
 
 private:
-  OptionDouble addopt;
+  OptionDouble addopt{true};
   OptionBool wgs84tomslopt;
   double addf{};
   // include static constexpr data member definitions with intializers for grid as private members.
@@ -56,7 +56,7 @@ private:
   QVector<arglist_t> args = {
     {
       "add", &addopt, "Adds a constant value to every altitude",
-      nullptr,  ARGTYPE_ALLOW_TRAILING_DATA | ARGTYPE_BEGIN_REQ | ARGTYPE_STRING, ARG_NOMINMAX, nullptr
+      nullptr, ARGTYPE_BEGIN_REQ | ARGTYPE_STRING, ARG_NOMINMAX, nullptr
     },
     {
       "wgs84tomsl", &wgs84tomslopt, "Converts WGS84 ellipsoidal height to orthometric height (MSL)",
index a0fd4cafd517b0a539e7eefa4a6cf7c62b49cc38..62d518fa66fafe7a6fc043386b0b49026df0b60d 100644 (file)
@@ -51,7 +51,7 @@ private:
 
   OptionDouble opt_time;
   double max_time_step{0};
-  OptionDouble opt_dist;
+  OptionDouble opt_dist{true};
   double max_dist_step{0};
   OptionBool opt_route;
 
@@ -63,7 +63,7 @@ private:
     },
     {
       "distance", &opt_dist, "Distance interval",
-      nullptr, ARGTYPE_END_EXCL | ARGTYPE_END_REQ | ARGTYPE_ALLOW_TRAILING_DATA | ARGTYPE_STRING,
+      nullptr, ARGTYPE_END_EXCL | ARGTYPE_END_REQ | ARGTYPE_STRING,
       ARG_NOMINMAX, nullptr
     },
     {
diff --git a/main.cc b/main.cc
index 41c5019c6ce2934323eb3d3c57393006dab15d17..426ea549d6af6d7c4ead7500664b7353ec3780ab 100644 (file)
--- a/main.cc
+++ b/main.cc
@@ -245,7 +245,7 @@ run_reader(Vecs::fmtinfo_t& ivecs, const QString& fname)
   start_session(ivecs.fmtname, fname);
   if (ivecs.isDynamic()) {
     ivecs.fmt = ivecs.factory(fname);
-    Vecs::init_vec(ivecs.fmt);
+    Vecs::init_vec(ivecs.fmt, ivecs.fmtname);
     Vecs::prepare_format(ivecs);
 
     ivecs->rd_init(fname);
@@ -277,7 +277,7 @@ run_writer(Vecs::fmtinfo_t& ovecs, const QString& ofname)
   }
   if (ovecs.isDynamic()) {
     ovecs.fmt = ovecs.factory(ofname);
-    Vecs::init_vec(ovecs.fmt);
+    Vecs::init_vec(ovecs.fmt, ovecs.fmtname);
     Vecs::prepare_format(ovecs);
 
     ovecs->wr_init(ofname);
@@ -462,7 +462,7 @@ run(const char* prog_name)
         }
         if (filter.isDynamic()) {
           filter.flt = filter.factory();
-          FilterVecs::init_filter_vec(filter.flt);
+          FilterVecs::init_filter_vec(filter.flt, filter.fltname);
           FilterVecs::prepare_filter(filter);
 
           filter->init();
@@ -650,11 +650,11 @@ run(const char* prog_name)
 
     if (ivecs.isDynamic()) {
       ivecs.fmt = ivecs.factory(fname);
-      Vecs::init_vec(ivecs.fmt);
+      Vecs::init_vec(ivecs.fmt, ivecs.fmtname);
     }
     if (ovecs && ovecs.isDynamic()) {
       ovecs.fmt = ovecs.factory(ofname);
-      Vecs::init_vec(ovecs.fmt);
+      Vecs::init_vec(ovecs.fmt, ovecs.fmtname);
     }
 
     start_session(ivecs.fmtname, fname);
index 8234bf0aa2813ef6c933cf7693fb42513c0910c9..282fcfcb728d810228ee23b90ab237ea04b1d123 100644 (file)
--- a/option.cc
+++ b/option.cc
@@ -53,11 +53,9 @@ double OptionString::toDouble(bool* ok, QString* end) const
   return parse_double(value_, id_, ok, end);
 }
 
-void OptionInt::init(const QString& id, bool allow_trailing_data, int base)
+void OptionInt::init(const QString& id)
 {
   id_ = id;
-  base_ = base;
-  allow_trailing_data_ = allow_trailing_data;
 }
 
 void OptionInt::reset()
@@ -77,6 +75,15 @@ void OptionInt::set(const QString& s)
   result_ = parse_integer(value_, id_, dieonerror, endp, base_);
 }
 
+bool OptionInt::isValid(const QString& s) const
+{
+  bool ok;
+  QString end;
+  QString* endp = allow_trailing_data_? &end : nullptr;
+  (void) parse_integer(s, id_, &ok, endp, base_);
+  return ok;
+}
+
 int OptionInt::get_result(QString* end) const
 {
   if (end != nullptr) {
@@ -85,10 +92,14 @@ int OptionInt::get_result(QString* end) const
   return result_;
 }
 
-void OptionDouble::init(const QString& id, bool allow_trailing_data, int /* base */)
+bool OptionInt::trailing_data_allowed() const
+{
+  return allow_trailing_data_;
+}
+
+void OptionDouble::init(const QString& id)
 {
   id_ = id;
-  allow_trailing_data_ = allow_trailing_data;
 }
 
 void OptionDouble::reset()
@@ -108,6 +119,15 @@ void OptionDouble::set(const QString& s)
   result_ = parse_double(value_, id_, dieonerror, endp);
 }
 
+bool OptionDouble::isValid(const QString& s) const
+{
+  bool ok;
+  QString end;
+  QString* endp = allow_trailing_data_? &end : nullptr;
+  (void) parse_double(s, id_, &ok, endp);
+  return ok;
+}
+
 double OptionDouble::get_result(QString* end) const
 {
   if (end != nullptr) {
@@ -115,3 +135,8 @@ double OptionDouble::get_result(QString* end) const
   }
   return result_;
 }
+
+bool OptionDouble::trailing_data_allowed() const
+{
+  return allow_trailing_data_;
+}
index f627dab659a9c334e96415d6d4edff58a9e5249b..b2f69b1312e08c9d5a2616dfda4daf218c09aef6 100644 (file)
--- a/option.h
+++ b/option.h
@@ -43,7 +43,7 @@ public:
   [[nodiscard]] virtual bool has_value() const = 0;
   [[nodiscard]] virtual bool isEmpty() const = 0;
   [[nodiscard]] virtual const QString& get() const = 0;
-  virtual void init(const QString& id, bool allow_trailing_data, int base) {}
+  virtual void init(const QString& id) {}
   virtual void reset() = 0;
   virtual void set(const QString& s) = 0;
 
@@ -83,7 +83,7 @@ public:
     return value_;
   }
 
-  void init(const QString& id, bool /* allow_trailing_data */, int /* base */) override
+  void init(const QString& id) override
   {
     id_ = id;
   }
@@ -116,6 +116,10 @@ class OptionInt : public Option
 public:
   /* Special Member Functions */
   OptionInt() = default;
+  explicit OptionInt(bool allow_trailing_data, int base) :
+    allow_trailing_data_(allow_trailing_data),
+    base_(base)
+  {}
 
   explicit(false) operator const QString& () const
   {
@@ -142,18 +146,20 @@ public:
     return value_;
   }
 
-  void init(const QString& id, bool allow_trailing_data, int base) override;
+  void init(const QString& id) override;
   void reset() override;
   void set(const QString& s) override;
+  bool isValid(const QString& s) const;
   int get_result(QString* end = nullptr) const;
+  bool trailing_data_allowed() const;
 
 private:
   QString value_;
   QString id_;
   int result_{};
   QString end_;
-  int base_{10};
   bool allow_trailing_data_{false};
+  int base_{10};
 };
 
 class OptionDouble : public Option
@@ -161,6 +167,9 @@ class OptionDouble : public Option
 public:
   /* Special Member Functions */
   OptionDouble() = default;
+  explicit OptionDouble(bool allow_trailing_data) :
+    allow_trailing_data_(allow_trailing_data)
+  {}
 
   explicit(false) operator const QString& () const
   {
@@ -187,10 +196,12 @@ public:
     return value_;
   }
 
-  void init(const QString& id, bool allow_trailing_data, int /* base */) override;
+  void init(const QString& id) override;
   void reset() override;
   void set(const QString& s) override;
+  bool isValid(const QString& s) const;
   double get_result(QString* end = nullptr) const;
+  bool trailing_data_allowed() const;
 
 private:
   QString value_;
diff --git a/ozi.h b/ozi.h
index 4f20a224519f2976fc28806e3836b54a9fa9a7e3..d24b423f310aca60c8006c350974c3a820beee1a 100644 (file)
--- a/ozi.h
+++ b/ozi.h
@@ -134,7 +134,7 @@ private:
   OptionString wptbgcolor;
   OptionBool pack_opt;
   int datum{};
-  OptionDouble proximityarg;
+  OptionDouble proximityarg{true};
   double proximity{};
   OptionString altunit_opt;
   OptionString proxunit_opt;
@@ -175,7 +175,7 @@ private:
     },
     {
       "proximity", &proximityarg, "Proximity distance",
-      "0",  ARGTYPE_ALLOW_TRAILING_DATA | ARGTYPE_STRING, ARG_NOMINMAX, nullptr
+      "0", ARGTYPE_STRING, ARG_NOMINMAX, nullptr
     },
     {
       "altunit", &altunit_opt, "Unit used in altitude values",
index 98b8e384e5adf624cca6995c66be0b9ba03f76a9..67df7f9c08694f7c167a67d3d49591866b3b5056 100644 (file)
@@ -64,7 +64,7 @@ private:
 
   double pos_dist{};
   qint64 max_diff_time{};
-  OptionDouble distopt;
+  OptionDouble distopt{true};
   OptionDouble timeopt;
   OptionBool purge_duplicates;
   bool check_time{};
@@ -72,7 +72,7 @@ private:
   QVector<arglist_t> args = {
     {
       "distance", &distopt, "Maximum positional distance",
-      nullptr,  ARGTYPE_ALLOW_TRAILING_DATA | ARGTYPE_STRING | ARGTYPE_REQUIRED, ARG_NOMINMAX, nullptr
+      nullptr, ARGTYPE_STRING | ARGTYPE_REQUIRED, ARG_NOMINMAX, nullptr
     },
     {
       "all", &purge_duplicates,
index 7f83d8929ce8aa9d7c559bfe5c65c0f89b3d1b35..96f1c67c3923b1452a1d3d54309e5d8c7891720f 100644 (file)
--- a/radius.h
+++ b/radius.h
@@ -55,7 +55,7 @@ private:
   /* Data Members */
 
   double pos_dist{};
-  OptionDouble distopt;
+  OptionDouble distopt{true};
   OptionDouble latopt;
   OptionDouble lonopt;
   OptionBool exclopt;
@@ -68,23 +68,23 @@ private:
 
   QVector<arglist_t> args = {
     {
-      "lat", &latopt,       "Latitude for center point (D.DDDDD)",
+      "lat", &latopt, "Latitude for center point (D.DDDDD)",
       nullptr, ARGTYPE_FLOAT | ARGTYPE_REQUIRED, ARG_NOMINMAX, nullptr
     },
     {
-      "lon", &lonopt,       "Longitude for center point (D.DDDDD)",
+      "lon", &lonopt, "Longitude for center point (D.DDDDD)",
       nullptr, ARGTYPE_FLOAT | ARGTYPE_REQUIRED, ARG_NOMINMAX, nullptr
     },
     {
       "distance", &distopt, "Maximum distance from center",
-      nullptr,  ARGTYPE_ALLOW_TRAILING_DATA | ARGTYPE_STRING | ARGTYPE_REQUIRED, ARG_NOMINMAX, nullptr
+      nullptr, ARGTYPE_STRING | ARGTYPE_REQUIRED, ARG_NOMINMAX, nullptr
     },
     {
-      "exclude", &exclopt,  "Exclude points close to center",
+      "exclude", &exclopt, "Exclude points close to center",
       nullptr, ARGTYPE_BOOL, ARG_NOMINMAX, nullptr
     },
     {
-      "nosort", &nosort,    "Inhibit sort by distance to center",
+      "nosort", &nosort, "Inhibit sort by distance to center",
       nullptr, ARGTYPE_BOOL, ARG_NOMINMAX, nullptr
     },
     {
diff --git a/reference/badopt1.txt b/reference/badopt1.txt
new file mode 100644 (file)
index 0000000..7fe10b9
--- /dev/null
@@ -0,0 +1 @@
+radius(lat): conversion to double failed: conversion of "44x" failed due to unexpected trailing data "x".
diff --git a/reference/badopt2.txt b/reference/badopt2.txt
new file mode 100644 (file)
index 0000000..9649222
--- /dev/null
@@ -0,0 +1 @@
+stack(depth): conversion to integer failed: invalid argument "b".
diff --git a/reference/badopt3.txt b/reference/badopt3.txt
new file mode 100644 (file)
index 0000000..63c3995
--- /dev/null
@@ -0,0 +1 @@
+gdb(bitscategory): conversion to integer failed: conversion of "0x2z" failed due to unexpected trailing data "z".
diff --git a/reference/badopt4.txt b/reference/badopt4.txt
new file mode 100644 (file)
index 0000000..ea15359
--- /dev/null
@@ -0,0 +1 @@
+csv(snlen): conversion to integer failed: invalid argument "a".
index 5852b03abbb686061f3bbadcfb342c1935d03589..fbfaa6d3692a37255a1c05b5a7fc0d356b8ea15f 100644 (file)
@@ -120,19 +120,19 @@ private:
   metric_t metric{metric_t::crosstrack};
 
   OptionInt countopt;
-  OptionDouble erroropt;
+  OptionDouble erroropt{true};
   OptionBool xteopt;
   OptionBool lenopt;
   OptionBool relopt;
 
   QVector<arglist_t> args = {
     {
-      "count", &countopt,  "Maximum number of points in route",
+      "count", &countopt, "Maximum number of points in route",
       nullptr, ARGTYPE_INT | ARGTYPE_BEGIN_REQ | ARGTYPE_BEGIN_EXCL, "1", nullptr, nullptr
     },
     {
       "error", &erroropt, "Maximum error", nullptr,
-       ARGTYPE_ALLOW_TRAILING_DATA | ARGTYPE_STRING | ARGTYPE_END_REQ | ARGTYPE_END_EXCL, "0", nullptr, nullptr
+       ARGTYPE_STRING | ARGTYPE_END_REQ | ARGTYPE_END_EXCL, "0", nullptr, nullptr
     },
     {
       "crosstrack", &xteopt, "Use cross-track error (default)", nullptr,
diff --git a/testo.d/vecs.test b/testo.d/vecs.test
new file mode 100644 (file)
index 0000000..a805c07
--- /dev/null
@@ -0,0 +1,18 @@
+# test detection of invalid option values
+# this should cover static and dynamic filters and functions.
+${VALGRIND} "${PNAME}" -i geo -f ${REFERENCE}/geocaching.loc -x radius,lat=44x -o gpx -F /dev/null 2> ${TMPDIR}/badopt1.txt && {
+  echo "${PNAME} succeeded! (it shouldn't have with this input...)"
+}
+compare ${REFERENCE}/badopt1.txt ${TMPDIR}/badopt1.txt
+${VALGRIND} "${PNAME}" -i geo -f ${REFERENCE}/geocaching.loc -x stack,depth=b -o gpx -F /dev/null 2> ${TMPDIR}/badopt2.txt && {
+  echo "${PNAME} succeeded! (it shouldn't have with this input...)"
+}
+compare ${REFERENCE}/badopt2.txt ${TMPDIR}/badopt2.txt
+${VALGRIND} "${PNAME}" -i gdb,bitscategory=0x2z -f ${REFERENCE}/gdb-sample.gdb -o xcsv -F /dev/null 2> ${TMPDIR}/badopt3.txt && {
+  echo "${PNAME} succeeded! (it shouldn't have with this input...)"
+}
+compare ${REFERENCE}/badopt3.txt ${TMPDIR}/badopt3.txt
+${VALGRIND} "${PNAME}" -i gdb,bitscategory=0x2 -f ${REFERENCE}/gdb-sample.gdb -o csv,snlen=a -F /dev/null 2> ${TMPDIR}/badopt4.txt && {
+  echo "${PNAME} succeeded! (it shouldn't have with this input...)"
+}
+compare ${REFERENCE}/badopt4.txt ${TMPDIR}/badopt4.txt
diff --git a/vecs.cc b/vecs.cc
index eb68674202d4db6008b9e24f7434c774b01d34de..6b07eaa60f0a6ff34201f07011ec1b75d9412426 100644 (file)
--- a/vecs.cc
+++ b/vecs.cc
@@ -500,7 +500,7 @@ Vecs& Vecs::Instance()
  * default initializer the default constructor would be implicitly deleted.
  */
 
-void Vecs::init_vec(Format* fmt)
+void Vecs::init_vec(Format* fmt, const QString& fmtname)
 {
   QVector<arglist_t>* args = fmt->get_args();
   if (args && !args->isEmpty()) {
@@ -508,6 +508,8 @@ void Vecs::init_vec(Format* fmt)
     for (auto& arg : *args) {
       if (arg.argval != nullptr) {
         arg.argval->reset();
+        QString id = QStringLiteral("%1(%2)").arg(fmtname, arg.argstring);
+        arg.argval->init(id);
       }
     }
   }
@@ -517,54 +519,12 @@ void Vecs::init_vecs()
 {
   for (const auto& vec : d_ptr_->vec_list) {
     if (vec.vec != nullptr) {
-      init_vec(vec.vec);
+      init_vec(vec.vec, vec.name);
     }
   }
   style_list = create_style_vec();
 }
 
-int Vecs::integer_base(uint32_t argtype)
-{
-  int base;
-  switch (argtype & ARGTYPE_BASEMASK) {
-  case ARGTYPE_BASE_AUTO:
-    base = 0;
-    break;
-  case ARGTYPE_BASE_16:
-    base = 16;
-    break;
-  case ARGTYPE_BASE_10:
-  default:
-    base = 10;
-  }
-  return base;
-
-}
-
-bool Vecs::trailing_data_allowed(uint32_t argtype)
-{
-  return (argtype & ARGTYPE_ALLOW_TRAILING_DATA) == ARGTYPE_ALLOW_TRAILING_DATA;
-}
-
-bool Vecs::is_integer(const QString& val, const QString& id, uint32_t argtype)
-{
-  bool ok;
-  int base = integer_base(argtype);
-  QString end;
-  QString* endp = trailing_data_allowed(argtype) ? &end : nullptr;
-  (void) parse_integer(val, id, &ok, endp, base);
-  return ok;
-}
-
-bool Vecs::is_float(const QString& val, const QString& id, uint32_t argtype)
-{
-  bool ok;
-  QString end;
-  QString* endp = trailing_data_allowed(argtype) ? &end : nullptr;
-  (void) parse_double(val, id, &ok, endp);
-  return ok;
-}
-
 bool Vecs::is_bool(const QString& val)
 {
   return val.startsWith('y', Qt::CaseInsensitive) ||
@@ -610,9 +570,6 @@ void Vecs::assign_option(const QString& module, arglist_t& arg, const QString& v
   }
 
   arg.argval->reset();
-  int base = integer_base(arg.argtype);
-  bool allow_trailing_data = trailing_data_allowed(arg.argtype);
-  arg.argval->init(id, allow_trailing_data, base);
 
   if (val.isNull()) {
     return;
@@ -1104,13 +1061,12 @@ bool Vecs::validate_args(const QString& name, const QVector<arglist_t>* args)
     }
 #endif
     for (const auto& arg : *args) {
-      QString id = QStringLiteral("%1(%2)").arg(name, arg.argstring);
       if (arg.argval == nullptr) {
         Warning() << name << "option" << arg.argstring << "does not point to an Option instance.";
         ok = false;
       }
       if (const auto* int_option = dynamic_cast<const OptionInt*>(arg.argval); int_option != nullptr) {
-        if (trailing_data_allowed(arg.argtype)) {
+        if (int_option->trailing_data_allowed()) {
           // GUI QIntValidator will reject input with trailing data.
           if ((arg.argtype & ARGTYPE_TYPEMASK) != ARGTYPE_STRING) {
             Warning() << name << "OptionInt with trailing data" << arg.argstring << "is not of ARGTYPE_STRING.";
@@ -1123,20 +1079,20 @@ bool Vecs::validate_args(const QString& name, const QVector<arglist_t>* args)
           }
         }
 
-        if (!arg.defaultvalue.isNull() && !is_integer(arg.defaultvalue, id, arg.argtype)) {
+        if (!arg.defaultvalue.isNull() && !int_option->isValid(arg.defaultvalue)) {
           Warning() << name << "Int option" << arg.argstring << "default value" << arg.defaultvalue << "is not an integer.";
           ok = false;
         }
-        if (!arg.minvalue.isNull() && !is_integer(arg.minvalue, id, arg.argtype)) {
+        if (!arg.minvalue.isNull() && !int_option->isValid(arg.minvalue)) {
           Warning() << name << "Int option" << arg.argstring << "minimum value" << arg.minvalue << "is not an integer.";
           ok = false;
         }
-        if (!arg.maxvalue.isNull() && !is_integer(arg.maxvalue, id, arg.argtype)) {
+        if (!arg.maxvalue.isNull() && !int_option->isValid(arg.maxvalue)) {
           Warning() << name << "Int option" << arg.argstring << "maximum value" << arg.maxvalue << "is not an integer.";
           ok = false;
         }
       } else if (const auto* double_option = dynamic_cast<const OptionDouble*>(arg.argval); double_option != nullptr) {
-        if (trailing_data_allowed(arg.argtype)) {
+        if (double_option->trailing_data_allowed()) {
           // GUI QDoubleValidator will reject input with trailing data.
           if ((arg.argtype & ARGTYPE_TYPEMASK) != ARGTYPE_STRING) {
             Warning() << name << "OptionDouble with trailing data" << arg.argstring << "is not of ARGTYPE_STRING.";
@@ -1149,15 +1105,15 @@ bool Vecs::validate_args(const QString& name, const QVector<arglist_t>* args)
           }
         }
 
-        if (!arg.defaultvalue.isNull() && !is_float(arg.defaultvalue, id, arg.argtype)) {
+        if (!arg.defaultvalue.isNull() && !double_option->isValid(arg.defaultvalue)) {
           Warning() << name << "Float option" << arg.argstring << "default value" << arg.defaultvalue << "is not an float.";
           ok = false;
         }
-        if (!arg.minvalue.isNull() && !is_float(arg.minvalue, id, arg.argtype)) {
+        if (!arg.minvalue.isNull() && !double_option->isValid(arg.minvalue)) {
           Warning() << name << "Float option" << arg.argstring << "minimum value" << arg.minvalue << "is not an float.";
           ok = false;
         }
-        if (!arg.maxvalue.isNull() && !is_float(arg.maxvalue, id, arg.argtype)) {
+        if (!arg.maxvalue.isNull() && !double_option->isValid(arg.maxvalue)) {
           Warning() << name << "Float option" << arg.argstring << "maximum value" << arg.maxvalue << "is not an float.";
           ok = false;
         }
diff --git a/vecs.h b/vecs.h
index 43676137bb7e62c34e7ce1eade218b8c5304e0ae..034ef38638a1bfc7d3ef228015ef7d83fa332eed 100644 (file)
--- a/vecs.h
+++ b/vecs.h
@@ -71,7 +71,7 @@ public:
 
   /* Member Functions */
 
-  static void init_vec(Format* fmt);
+  static void init_vec(Format* fmt, const QString& fmtname);
   void init_vecs();
   static void free_options(QVector<arglist_t>* args);
   static void exit_vec(Format* fmt);
@@ -143,10 +143,6 @@ private:
 
   /* Member Functions */
 
-  static int integer_base(uint32_t argtype);
-  static bool trailing_data_allowed(uint32_t argtype);
-  static bool is_integer(const QString& val, const QString& id, uint32_t argtype);
-  static bool is_float(const QString& val, const QString& id, uint32_t argtype);
   static bool is_bool(const QString& val);
   static QVector<style_vec_t> create_style_vec();
   QVector<vecinfo_t> sort_and_unify_vecs() const;